Add global --sdk and --jdk path overrides for all Android commands#139
Conversation
--sdk and --jdk path overrides for all Android commands
|
/review |
There was a problem hiding this comment.
Pull request overview
Adds global --sdk and --jdk path override options to the maui android command group so nested subcommands can be run against non-default Android SDK/JDK locations.
Changes:
- Add
OverrideSdkPath(string)/OverrideJdkPath(string)toIAndroidProviderand implement inAndroidProvider/FakeAndroidProvider. - Introduce recursive
--sdk/--jdkoptions on theandroidparent command and apply them viaGetAndroidProvider(ParseResult)across Android subcommands. - Add unit tests validating option presence/recursion/parsing and basic override propagation via
FakeAndroidProvider.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Cli/Microsoft.Maui.Cli/Providers/Android/IAndroidProvider.cs | Adds new per-session override methods for SDK/JDK paths. |
| src/Cli/Microsoft.Maui.Cli/Providers/Android/AndroidProvider.cs | Implements override methods by setting backing fields. |
| src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.cs | Defines recursive --sdk/--jdk options and applies them when resolving the provider. |
| src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.Sdk.cs | Switches SDK subcommands to use GetAndroidProvider(parseResult). |
| src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.Install.cs | Switches install command to use GetAndroidProvider(parseResult). |
| src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.Emulator.cs | Switches emulator subcommands to use GetAndroidProvider(parseResult). |
| src/Cli/Microsoft.Maui.Cli.UnitTests/Fakes/FakeAndroidProvider.cs | Adds override methods for testing. |
| src/Cli/Microsoft.Maui.Cli.UnitTests/AndroidCommandsTests.cs | Adds tests for the new options and override behavior. |
There was a problem hiding this comment.
Expert Code Review — PR #139: Global --sdk and --jdk path overrides
Methodology: 3 independent reviewers with adversarial consensus. Findings below were validated by at least 2/3 reviewers; disputed findings were re-evaluated with targeted follow-up.
CI Status: ✅ Builds pass on both macOS and Windows. CLA check passed. 9 new unit tests all pass.
Findings by Severity
| # | Severity | Consensus | File | Finding |
|---|---|---|---|---|
| 1 | 🔴 CRITICAL | 3/3 reviewers | AndroidProvider.cs |
OverrideSdkPath/OverrideJdkPath don't propagate to AvdManager or Adb — they eagerly resolve paths in their constructors. All emulator and ADB-dependent commands silently use the original paths after override. |
| 2 | 🟡 MODERATE | 3/3 reviewers | AndroidCommands.cs |
GetAndroidProvider mutates the singleton IAndroidProvider, leaking state across invocations. Safe today (single command per process) but fragile. |
| 3 | 🟡 MODERATE | 2/3 reviewers | AndroidCommands.cs |
--jdk is Recursive but silently ignored by all jdk subcommands, which use Program.JdkManager independently. |
| 4 | 🟡 MODERATE | 2/3 reviewers | AndroidCommands.Install.cs |
--sdk (parent) and --sdk-path (install subcommand) have confusingly similar names and conflicting semantics. |
| 5 | 🟢 MINOR | 2/3 reviewers | AndroidCommands.cs |
No validation on override paths — whitespace and non-existent paths accepted silently. |
| 6 | 🟢 MINOR | 3/3 reviewers | AndroidCommandsTests.cs |
Tests use FakeAndroidProvider (property bag) so they can't detect the real propagation bug in Finding 1. |
Test Coverage Assessment
The 9 new tests provide good coverage of the CLI parsing layer (option presence, recursion, parsing on nested subcommands) and the override call chain through the fake provider. However, no test exercises the real AndroidProvider path propagation to downstream tools, leaving Finding 1 (the critical bug) undetected by the test suite.
Summary
The CLI plumbing and option design are clean and well-structured. The critical issue is that the override mechanism only fully works for SdkManager commands — AvdManager and Adb eagerly bake in paths at construction time and are unaffected by later overrides. This should be addressed before merge to avoid silent misbehavior when users pass --sdk/--jdk with emulator or ADB-dependent commands.
Generated by Expert Code Review (auto) for issue #139 · ● 6.6M
…ands Add --sdk and --jdk as recursive options on the 'maui android' parent command, matching Google's android CLI --sdk pattern. These override the Android SDK and JDK paths for any subcommand (sdk, emulator, install, jdk) without changing environment variables. - Add OverrideSdkPath/OverrideJdkPath to IAndroidProvider interface - Implement in AndroidProvider (sets internal _sdkPath/_jdkPath fields) - Add GetAndroidProvider(ParseResult) helper that applies overrides - Update all 11 command handlers to use the helper - Add 9 unit tests covering option parsing and provider override propagation Agent-Logs-Url: https://github.com/dotnet/maui-labs/sessions/b4e83a34-2e30-4f70-a703-7fb68ff1a221 Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
…nd naming - Fix critical bug: OverrideSdkPath/OverrideJdkPath now rebuild Adb and AvdManager instances so overrides propagate to all downstream tools - Add Directory.Exists validation for --sdk/--jdk paths (hard error) - Use IsNullOrWhiteSpace instead of IsNullOrEmpty for path checks - Rename --sdk-path to --sdk-install-path on install command to avoid confusion with the parent --sdk option - Update XML docs to accurately describe override rebuild behavior - Document singleton mutation assumption in GetAndroidProvider - Clarify --jdk description: affects Android SDK tools, not jdk subcommands - Add real AndroidProvider override propagation tests - Add path validation tests (nonexistent paths, whitespace) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e8508be to
9246fd3
Compare
#139) * Initial plan * Add global --sdk and --jdk path override options for all android commands Add --sdk and --jdk as recursive options on the 'maui android' parent command, matching Google's android CLI --sdk pattern. These override the Android SDK and JDK paths for any subcommand (sdk, emulator, install, jdk) without changing environment variables. - Add OverrideSdkPath/OverrideJdkPath to IAndroidProvider interface - Implement in AndroidProvider (sets internal _sdkPath/_jdkPath fields) - Add GetAndroidProvider(ParseResult) helper that applies overrides - Update all 11 command handlers to use the helper - Add 9 unit tests covering option parsing and provider override propagation Agent-Logs-Url: https://github.com/dotnet/maui-labs/sessions/b4e83a34-2e30-4f70-a703-7fb68ff1a221 Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com> * Address review feedback: fix override propagation, path validation, and naming - Fix critical bug: OverrideSdkPath/OverrideJdkPath now rebuild Adb and AvdManager instances so overrides propagate to all downstream tools - Add Directory.Exists validation for --sdk/--jdk paths (hard error) - Use IsNullOrWhiteSpace instead of IsNullOrEmpty for path checks - Rename --sdk-path to --sdk-install-path on install command to avoid confusion with the parent --sdk option - Update XML docs to accurately describe override rebuild behavior - Document singleton mutation assumption in GetAndroidProvider - Clarify --jdk description: affects Android SDK tools, not jdk subcommands - Add real AndroidProvider override propagation tests - Add path validation tests (nonexistent paths, whitespace) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com> Co-authored-by: Rui Marinho <me@ruimarinho.net> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
All
maui androidsubcommands use auto-detected SDK/JDK paths with no per-invocation override. Onlymaui android installhad--sdk-path. This adds--sdkand--jdkas recursive options on theandroidparent command, matching Google'sandroid --sdk=<path>pattern.Interface
OverrideSdkPath(string)/OverrideJdkPath(string)toIAndroidProvider_sdkPath/_jdkPathfields, which propagate through the existingFunc<string?>lambdas toSdkManager,AvdManager, andAdbCLI plumbing
--sdkand--jdkdefined asRecursive = trueOption<string>on theandroidparent commandGetAndroidProvider(ParseResult)helper reads both options and calls the override methods before returning the providerSdk,Emulator,Install, andJdkupdated fromProgram.AndroidProvider→GetAndroidProvider(parseResult)Tests
Recursiveflag, parsing on nested subcommands (sdk list,jdk check,emulator list), and end-to-end provider override propagation viaFakeAndroidProviderScope note
--jdkpropagates throughAndroidProvider.JdkPath(used bySdkManager/AvdManager). Pure JDK commands (jdk check/list/install) useJdkManagerdirectly and are unaffected — follow-up if needed.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
7k6vsblobprodcus337.vsblob.vsassets.io/usr/bin/dotnet dotnet build src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj --no-restore(dns block)c50vsblobprodcus330.vsblob.vsassets.io/usr/bin/dotnet dotnet build src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj --no-restore(dns block)/usr/bin/dotnet dotnet restore src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj owner --uid-owner 0 -j ACCEPT(dns block)/usr/bin/dotnet dotnet restore src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj --verbosity minimal(dns block)If you need me to access, download, or install something from one of these locations, you can either: